#!/usr/bin/perl -w 

use strict;
use XML::LibXML;

my $source_file = shift;

my $parser = XML::LibXML->new();
my $tree = $parser->parse_file($source_file);
my $xpc = XML::LibXML::XPathContext->new($tree);
my @n = $xpc->findnodes('//sourcecode'); 

my %tanglefile;
my @outline;

foreach my $nod (@n) {
    $tanglefile{$nod->getAttribute('fragment_id')} =  $nod->getFirstChild()->getData;
}

open OUTLINE, 'outline' or die "Can't open the outline file: $!";

while (<OUTLINE>) {
    chomp;
    push @outline, $_;
}


foreach my $id (@outline) {
    print $tanglefile{$id};
}
